package com.usian.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.order.fegin.AccountFegin;
import com.usian.order.fegin.StockFegin;
import com.usian.order.mapper.OrderMapper;
import com.usian.order.model.Order;
import com.usian.order.service.OrderService;
import com.usian.order.vo.Account;
import com.usian.order.vo.Stock;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author baimugudu
 * @email 2415621370@qq.com
 * @date 2023/8/11 14:04
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order>
implements OrderService {

    @Autowired(required = false)
    AccountFegin accountFegin;

    @Autowired(required = false)
    StockFegin stockFegin;


    @Override
    @GlobalTransactional
    public void createOrder(Order order){

        //order表插入数据
        this.baseMapper.insert(order);


        //修改账户余额
        Account account = new Account();
        account.setId(1L);
        account.setBalance(100L);
        accountFegin.updateAcc(account);

        //编写扣减库存的方法：
        Stock stock = new Stock();
        stock.setId(1L);
        stock.setNum(100L);
        stockFegin.updateStock(stock);

    }
}
